<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Parsedown;

class PetResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return
            [
                'article' => $this->article->title,
                'price' => $this->extra['price'],
                'time' => $this->extra['time'],
                'content' => $this->markdown($this->content),
            ] + parent::toArray($request);
    }

    public function markdown($content)
    {
        $parsedown = new Parsedown();
        return $parsedown->text($content);
    }
}
